namespace SimpleWebServices.Web
{
    using System.Xml.XPath;
    using SimpleWebServices;
    using SimpleWebServices.Web.Mvc;
    using Xunit;

    public sealed class MovedPermanentlyFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<MovedPermanently>()
                .DerivesFrom<Redirection>()
                .IsConcreteClass()
                .IsUnsealed()
                .HasDefaultConstructor()
                .XmlRoot("redirection")
                .Result);
        }

        [Fact]
        public void deserialize()
        {
            MovedPermanently actual = "<redirection location='/path' />".Deserialize<MovedPermanently>();

            Assert.NotNull(actual);

            Assert.Equal<string>("/path", actual.Location);
        }

        [Fact]
        public void deserializeEmpty()
        {
            MovedPermanently actual = "<redirection />".Deserialize<MovedPermanently>();

            Assert.NotNull(actual);

            Assert.Null(actual.Location);
        }

        [Fact]
        public void serialize()
        {
            MovedPermanently obj = new MovedPermanently
            {
                Location = "/path"
            };

            IXPathNavigable xml = obj.Serialize();

            string xpath = "1=count(/redirection[@location='/path'])";

            Assert.True((bool)xml.CreateNavigator().Evaluate(xpath));
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new MovedPermanently());
        }

        [Fact]
        public void ctor_string()
        {
            string expected = "/path";
            string actual = new MovedPermanently(expected).Location;

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToActionResult()
        {
            MovedPermanently obj = new MovedPermanently
            {
                Location = "/path"
            };

            Assert.IsAssignableFrom<MovedPermanentlyResult>(obj.ToActionResult());
        }
    }
}